import { vProps, vEvent } from './propsType'

export default function createPool(dom, methods) {

  const propsPool = new Map()
  const eventPool = new Map()
  const allNodes = dom.getElementsByTagName('*')
  const { vIf, vShow } = vProps
  const { vClick } = vEvent

  let node = null

  for (let i = 0; i < allNodes.length; i++) {
    node = allNodes[i]

    const vIfVal = node.getAttribute(vIf)
    const vShowVal = node.getAttribute(vShow)
    const vClickEventName = node.getAttribute('@' + vClick)

    if (vIfVal) {
      propsPool.set(node, {
        type: vIf,
        prop: vIfVal
      })

      node.removeAttribute(vIf)
    } else if (vShowVal) {
      propsPool.set(node, {
        type: vShow,
        prop: vShowVal
      })
      node.removeAttribute(vShow)
    } else { }

    if (vClickEventName) {
      eventPool.set(node, {
        type: vClick,
        handle: methods[vClickEventName]
      })
      node.removeAttribute(vClick)
    }

  }

  return {
    propsPool,
    eventPool
  }
}